<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Requests\Base\ShopProductSpecNumberRequest;
use App\Library\Requests\Help\HelpPageRequest;
use App\Library\Requests\Help\HelpOrderRequest;
use App\Library\Service\HelpService;
use Illuminate\Http\JsonResponse;

class HelpController extends BaseController
{
    public function __construct(HelpService $service)
    {
        return $this->service = $service;
    }

    /**
     * create
     * @param ShopProductSpecNumberRequest $request
     * @return JsonResponse
     */
    public function create(ShopProductSpecNumberRequest $request): JsonResponse
    {
        return Lock::get(USERID . __CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->create($request);
        });
    }

    /**
     * get
     * @param ShopProductSpecNumberRequest $request
     * @return JsonResponse
     */
    public function get(ShopProductSpecNumberRequest $request): JsonResponse
    {
        return Lock::get($request->serialNumber . __CLASS__ . __FUNCTION__ . USERID, function () use ($request) {
            return $this->service->get($request);
        });
    }

    /**
     * cut
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function cut(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->cut($request);
        });
    }

    /**
     * recordPaging
     * @param HelpPageRequest $request
     * @return JsonResponse
     */
    public function recordPaging(HelpPageRequest $request): JsonResponse
    {
        return $this->service->recordPaging($request);
    }

    /**
     * order
     * @param HelpOrderRequest $request
     * @return JsonResponse
     */
    public function order(HelpOrderRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->order($request);
        });
    }
}
